package logic

import (
	"context"
	"github.com/google/uuid"
	"gorm.io/gorm"
	"member_srv/model/mysql"

	"member_srv/internal/svc"
	"member_srv/member"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddMemberLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddMemberLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddMemberLogic {
	return &AddMemberLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddMemberLogic) AddMember(in *member.AddMemberRequest) (*member.AddMemberResponse, error) {
	orderSn := uuid.NewString()
	m := mysql.Member{
		Model:   gorm.Model{},
		Title:   in.Title,
		Price:   float64(in.Price),
		OrderSn: orderSn,
		Types:   in.Types,
		UserId:  1,
	}
	err := m.Create()
	if err != nil {
		logx.Error("会员充值下单存储失败", err)
		return nil, err
	}

	return &member.AddMemberResponse{}, nil
}
